package cn.baiyang.rocketmq.spring.core;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

import org.apache.rocketmq.client.apis.message.MessageView;

/**
 *
 * @author hongzhu
 * @version V1.0
 * @since 2023-07-27 09:24
 */
public class RocketMQListenerHelper {

    protected byte[] getBody(MessageView messageView) {
        ByteBuffer byteBuffer = messageView.getBody();
        byte[] body = new byte[byteBuffer.remaining()];
        byteBuffer.get(body);
        return body;
    }

    protected String getBodyAsString(MessageView messageView) {
        return StandardCharsets.UTF_8.decode(messageView.getBody()).toString();
    }

}
